package com.star.string;

import java.util.Scanner;

public class PatternTest {

    public static void main(String[] args) {
        // 写一个方法,用于验证手机号码是否符合正则

        // 从终端获取用户输入
        while (true) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入手机号码");
            String phone = scanner.nextLine();
            String regex = "1[3456789][0-9]{9}";
            boolean matches = phone.matches(regex);

            if (matches) {
                System.out.println("手机号码格式正确");
            } else {
                System.out.println("手机号码格式错误");
            }

        }

    }
}
